package org.example.page194.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.example.page194.entity.User;
import org.example.page194.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class LoginController {
    @Autowired
    private UserService userService;
    @RequestMapping("/userList")
    public String userList(){
        return "userList";
    }
    @RequestMapping("/login")
    public String login(User user, HttpServletRequest request){
        User user2 = userService.getUserByUserName(user.getUserName());
        if(user2 != null && user.getPassword().equals(user2.getPassword())){
            HttpSession session = request.getSession();
            session.setAttribute("LoginUser", user2);
            return "redirect:/getProductList";
        }
        request.setAttribute("msg", "账号或密码错误");
        return "userList";
    }
}
